#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>

using namespace std;

int days, lollies[100], delay[100], dp[100], prev[100];

int main()
{
	int caseno = 0, d;
	char title[20];
	stack<int> ans;

	while (++caseno)
	{
		if (scanf("%s", title) != 1 || title[0] == '#')
			return 0;
		else if (caseno > 1)
			printf("\n");

		days = 0;
		while (scanf("%i%i", lollies + days, delay + days) == 2)
			days++;

		fill(dp, dp + 100, 0);
		fill(prev, prev + 100, -1);
		for (int i = 0; i < days; i++)
		{
			dp[i] = lollies[i];
			for (int j = 0; j < i; j++)
				if (lollies[i] + dp[j] > dp[i] && j + delay[j] <= i)
				{
					dp[i] = lollies[i] + dp[j];
					prev[i] = j;
				}
		}

		d = max_element(dp, dp + days) - dp;
		printf("In %s %i loll%s can be obtained:\n", title, dp[d], dp[d] != 1 ? "ies" : "y");

		while (d != -1)
		{
			ans.push(d);
			d = prev[d];
		}
		while (!ans.empty())
		{
			d = ans.top();
			ans.pop();
			printf("On day %i collect %i loll%s.\n", d + 1, lollies[d], lollies[d] != 1 ? "ies" : "y");
		}
	}
}
